<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>关联优惠券</title>
    <link rel="stylesheet" href="${base}/jstool/ztreev3/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${base}/jstool/ztreev3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="${base}/jstool/ztreev3/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${base}/jstool/ztreev3/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${base}/jstool/ztreev3/js/jquery.ztree.excheck.js"></script>
</head>

<body>
<SCRIPT type="text/javascript">
    <!--
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };

    var zNodes =[
        <#list czjawardstocks as w>
    <#if w_index!=0> , </#if>
    {
        id:"${w.awardstockId!}",
        pId:0,
        name:"${w.thingName!}",
       checked:${w.ispermission?string("true","false")},
        open:true
    }

    </#list>

    ];

    var code;



    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);

    });
    //-->
</SCRIPT>
<!--<div class="zTreeDemoBackground left">-->
    <ul id="treeDemo" class="ztree"></ul>
<!--</div>-->
<!--<button id="tijiaotree" onclick="setcode(roleId)" hidden>按钮</button>-->
<script type="text/javascript">
    function setcode(){
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getCheckedNodes(true);
       /* var msg = "name--id--pid\n";
        for (var i = 0; i < nodes.length; i++) {
            msg += nodes[i].name+"--"+nodes[i].id+"--"+nodes[i].pId+"\n";
        }
        console.log(msg);*/
        var awardstockIds = new Array();

        for (var i = 0; i < nodes.length; i++) {
        	awardstockIds.push(nodes[i].id);
        }
        $.ajax({
            url:"${base}/busin/saveCzjawardstock",
            type: "POST",
            data:{
            	awardstockIds:awardstockIds,
            	commodityId:"${commodityId!}"
            },
            success: function(){
                alert('关联优惠券成功！');
            },
            error:function(data){
                console.log(data.responseText);
//                alert('更新角色用户失败！详情：<br/>'+data);
            }
        });
    }
</script>
</body>
</html>